home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / vol_300 / 335_03 / as8096.y < prev    next >
Text File  |  1990-12-02  |  58KB  |  2,143 lines

  1. %{
  2.  
  3. /*
  4. HEADER:     ;
  5. TITLE:         Frankenstein Cross Assemblers;
  6. VERSION:     2.0;
  7. DESCRIPTION: "    Reconfigurable Cross-assembler producing Intel (TM)
  8.         Hex format object records.  ";
  9. KEYWORDS:     cross-assemblers, 1805, 2650, 6301, 6502, 6805, 6809, 
  10.         6811, tms7000, 8048, 8051, 8096, z8, z80;
  11. SYSTEM:     UNIX, MS-Dos ;
  12. FILENAME:     as8096.y;
  13. WARNINGS:     "This software is in the public domain.  
  14.         Any prior copyright claims are relinquished.  
  15.  
  16.         This software is distributed with no warranty whatever.  
  17.         The author takes no responsibility for the consequences 
  18.         of its use.
  19.  
  20.         Yacc (or Bison) required to compile."  ;
  21. SEE-ALSO:     as8096.doc,frasmain.c;    
  22. AUTHORS:     Mark Zenier;
  23. COMPILERS:     Microport Sys V/AT, ATT Yacc, Turbo C V1.5, Bison (CUG disk 285)
  24.         (previous versions Xenix, Unisoft 68000 Version 7, Sun 3);
  25. */
  26. /* 8096 instruction generation file */
  27. /* November 17, 1990 */
  28.  
  29. /*
  30.     description    frame work parser description for framework cross
  31.             assemblers
  32.     history        February 2, 1988
  33.             September 11, 1990 - merge table definition
  34.             September 12, 1990 - short file names
  35.             September 14, 1990 - short variable names
  36.             September 17, 1990 - use yylex as external
  37. */
  38. #include <stdio.h>
  39. #include "frasmdat.h"
  40. #include "fragcon.h"
  41.  
  42. #define yylex lexintercept
  43.  
  44. /*    0000.0000.0000.00xx    short/long index selection */
  45. #define    ADDR        0x3
  46. #define    DIRECT        0x1
  47. #define    EXTENDED    0x2
  48. /*    0000.0000.0000.x000    80196 select */
  49. #define    CPU196        0x8
  50. #define    CPU96        0
  51. #define ST_INH 0x1
  52. #define ST_DIR1 0x2
  53. #define ST_DIR2 0x4
  54. #define ST_DIR3 0x8
  55. #define ST_IMM1 0x10
  56. #define ST_IMM2 0x20
  57. #define ST_IMM3 0x40
  58. #define ST_IND1 0x80
  59. #define ST_INC1 0x100
  60. #define ST_IND2 0x200
  61. #define ST_INC2 0x400
  62. #define ST_IND3 0x800
  63. #define ST_INC3 0x1000
  64. #define ST_INX1 0x2000
  65. #define ST_INX2 0x4000
  66. #define ST_INX3 0x8000
  67.     
  68.     int    cpuselect = CPU196;
  69.     static char    genbdef[] = "[1=];";
  70.     static char    genwdef[] = "[1=]y"; /* x for normal, y for byte rev */
  71.     char ignosyn[] = "[Xinvalid syntax for instruction";
  72.     char ignosel[] = "[Xinvalid operands/illegal instruction for cpu";
  73. /*    constants for increment bit in indirect operand */
  74. #define    AUTOINC        1
  75. #define    NOINC        0
  76.  
  77.     long    labelloc;
  78.     static int satsub;
  79.     int    ifstkpt = 0;
  80.     int    fraifskip = FALSE;
  81.  
  82.     struct symel * endsymbol = SYMNULL;
  83.  
  84. %}
  85. %union {
  86.     int    intv;
  87.     long     longv;
  88.     char    *strng;
  89.     struct symel *symb;
  90. }
  91.  
  92. %token <intv> KOC_WDEF
  93. %token <intv> KOC_BDEF
  94. %token <intv> KOC_ELSE
  95. %token <intv> KOC_END
  96. %token <intv> KOC_ENDI
  97. %token <intv> KOC_EQU
  98. %token <intv> KOC_IF
  99. %token <intv> KOC_INCLUDE
  100. %token <intv> KOC_ORG
  101. %token <intv> KOC_RESM
  102. %token <intv> KOC_SDEF
  103. %token <intv> KOC_SET
  104. %token <intv> KOC_CHSET
  105. %token <intv> KOC_CHDEF
  106. %token <intv> KOC_CHUSE
  107. %token <intv> KOC_AWRESM
  108. %token <intv> KOC_ALRESM
  109. %token <intv> KOC_ALDEF
  110. %token <intv> KOC_AWDEF
  111. %token <intv> KOC_CPU
  112. %token <intv> KOC_opcode
  113.  
  114. %token <longv> CONSTANT
  115. %token EOL
  116. %token KEOP_AND
  117. %token KEOP_DEFINED
  118. %token KEOP_EQ
  119. %token KEOP_GE
  120. %token KEOP_GT
  121. %token KEOP_HIGH
  122. %token KEOP_LE
  123. %token KEOP_LOW
  124. %token KEOP_LT
  125. %token KEOP_MOD
  126. %token KEOP_MUN
  127. %token KEOP_NE
  128. %token KEOP_NOT
  129. %token KEOP_OR
  130. %token KEOP_SHL
  131. %token KEOP_SHR
  132. %token KEOP_XOR
  133. %token KEOP_locctr
  134. %token <symb> LABEL
  135. %token <strng> STRING
  136. %token <symb> SYMBOL
  137.  
  138. %token KTK_invalid
  139.  
  140. %right    KEOP_HIGH KEOP_LOW
  141. %left    KEOP_OR KEOP_XOR
  142. %left    KEOP_AND
  143. %right    KEOP_NOT
  144. %nonassoc    KEOP_GT KEOP_GE KEOP_LE KEOP_LT KEOP_NE KEOP_EQ
  145. %left    '+' '-'
  146. %left    '*' '/' KEOP_MOD KEOP_SHL KEOP_SHR
  147. %right    KEOP_MUN
  148.  
  149.  
  150. %type <intv> expr exprlist stringlist
  151.  
  152. %start file
  153.  
  154. %%
  155.  
  156. file    :    file allline
  157.     |    allline
  158.     ;
  159.  
  160. allline    :     line EOL
  161.             {
  162.                 clrexpr();
  163.             }
  164.     |    EOL
  165.     |    error EOL
  166.             {
  167.                 clrexpr();
  168.                 yyerrok;
  169.             }
  170.     ;
  171.  
  172. line    :    LABEL KOC_END 
  173.             {
  174.                 endsymbol = $1;
  175.                 nextreadact = Nra_end;
  176.             }
  177.     |          KOC_END 
  178.             {
  179.                 nextreadact = Nra_end;
  180.             }
  181.     |    KOC_INCLUDE STRING
  182.             {
  183.         if(nextfstk >= FILESTKDPTH)
  184.         {
  185.             fraerror("include file nesting limit exceeded");
  186.         }
  187.         else
  188.         {
  189.             infilestk[nextfstk].fnm = savestring($2,strlen($2));
  190.             if( (infilestk[nextfstk].fpt = fopen($2,"r"))
  191.                 ==(FILE *)NULL )
  192.             {
  193.                 fraerror("cannot open include file");
  194.             }
  195.             else
  196.             {
  197.                 nextreadact = Nra_new;
  198.             }
  199.         }
  200.             }
  201.     |    LABEL KOC_EQU expr 
  202.             {
  203.                 if($1 -> seg == SSG_UNDEF)
  204.                 {
  205.                     pevalexpr(0, $3);
  206.                     if(evalr[0].seg == SSG_ABS)
  207.                     {
  208.                         $1 -> seg = SSG_EQU;
  209.                         $1 -> value = evalr[0].value;
  210.                         prtequvalue("C: 0x%lx\n",
  211.                             evalr[0].value);
  212.                     }
  213.                     else
  214.                     {
  215.                         fraerror(
  216.                     "noncomputable expression for EQU");
  217.                     }
  218.                 }
  219.                 else
  220.                 {
  221.                     fraerror(
  222.                 "cannot change symbol value with EQU");
  223.                 }
  224.             }
  225.     |    LABEL KOC_SET expr 
  226.             {
  227.                 if($1 -> seg == SSG_UNDEF
  228.                    || $1 -> seg == SSG_SET)
  229.                 {
  230.                     pevalexpr(0, $3);
  231.                     if(evalr[0].seg == SSG_ABS)
  232.                     {
  233.                         $1 -> seg = SSG_SET;
  234.                         $1 -> value = evalr[0].value;
  235.                         prtequvalue("C: 0x%lx\n",
  236.                             evalr[0].value);
  237.                     }
  238.                     else
  239.                     {
  240.                         fraerror(
  241.                     "noncomputable expression for SET");
  242.                     }
  243.                 }
  244.                 else
  245.                 {
  246.                     fraerror(
  247.                 "cannot change symbol value with SET");
  248.                 }
  249.             }
  250.     |    KOC_IF expr 
  251.             {
  252.         if((++ifstkpt) < IFSTKDEPTH)
  253.         {
  254.             pevalexpr(0, $2);
  255.             if(evalr[0].seg == SSG_ABS)
  256.             {
  257.                 if(evalr[0].value != 0)
  258.                 {
  259.                     elseifstk[ifstkpt] = If_Skip;
  260.                     endifstk[ifstkpt] = If_Active;
  261.                 }
  262.                 else
  263.                 {
  264.                     fraifskip = TRUE;
  265.                     elseifstk[ifstkpt] = If_Active;
  266.                     endifstk[ifstkpt] = If_Active;
  267.                 }
  268.             }
  269.             else
  270.             {
  271.                 fraifskip = TRUE;
  272.                 elseifstk[ifstkpt] = If_Active;
  273.                 endifstk[ifstkpt] = If_Active;
  274.             }
  275.         }
  276.         else
  277.         {
  278.             fraerror("IF stack overflow");
  279.         }
  280.             }
  281.                         
  282.     |    KOC_IF 
  283.             {
  284.         if(fraifskip) 
  285.         {
  286.             if((++ifstkpt) < IFSTKDEPTH)
  287.             {
  288.                     elseifstk[ifstkpt] = If_Skip;
  289.                     endifstk[ifstkpt] = If_Skip;
  290.             }
  291.             else
  292.             {
  293.                 fraerror("IF stack overflow");
  294.             }
  295.         }
  296.         else
  297.         {
  298.             yyerror("syntax error");
  299.             YYERROR;
  300.         }
  301.                 }
  302.                         
  303.     |    KOC_ELSE 
  304.             {
  305.                 switch(elseifstk[ifstkpt])
  306.                 {
  307.                 case If_Active:
  308.                     fraifskip = FALSE;
  309.                     break;
  310.                 
  311.                 case If_Skip:
  312.                     fraifskip = TRUE;
  313.                     break;
  314.                 
  315.                 case If_Err:
  316.                     fraerror("ELSE with no matching if");
  317.                     break;
  318.                 }
  319.             }
  320.  
  321.     |    KOC_ENDI 
  322.             {
  323.                 switch(endifstk[ifstkpt])
  324.                 {
  325.                 case If_Active:
  326.                     fraifskip = FALSE;
  327.                     ifstkpt--;
  328.                     break;
  329.                 
  330.                 case If_Skip:
  331.                     fraifskip = TRUE;
  332.                     ifstkpt--;
  333.                     break;
  334.                 
  335.                 case If_Err:
  336.                     fraerror("ENDI with no matching if");
  337.                     break;
  338.                 }
  339.             }
  340.     |    LABEL KOC_ORG expr 
  341.             {
  342.                 pevalexpr(0, $3);
  343.                 if(evalr[0].seg == SSG_ABS)
  344.                 {
  345.                     locctr = labelloc = evalr[0].value;
  346.                     if($1 -> seg == SSG_UNDEF)
  347.                     {
  348.                         $1 -> seg = SSG_ABS;
  349.                         $1 -> value = labelloc;
  350.                     }
  351.                     else
  352.                         fraerror(
  353.                         "multiple definition of label");
  354.                     prtequvalue("C: 0x%lx\n",
  355.                         evalr[0].value);
  356.                 }
  357.                 else
  358.                 {
  359.                     fraerror(
  360.                      "noncomputable expression for ORG");
  361.                 }
  362.             }
  363.     |          KOC_ORG expr 
  364.             {
  365.                 pevalexpr(0, $2);
  366.                 if(evalr[0].seg == SSG_ABS)
  367.                 {
  368.                     locctr = labelloc = evalr[0].value;
  369.                     prtequvalue("C: 0x%lx\n",
  370.                         evalr[0].value);
  371.                 }
  372.                 else
  373.                 {
  374.                     fraerror(
  375.                      "noncomputable expression for ORG");
  376.                 }
  377.             }
  378.     |    LABEL KOC_CHSET
  379.             {
  380.                 if($1 -> seg == SSG_UNDEF)
  381.                 {
  382.                     $1 -> seg = SSG_EQU;
  383.                     if( ($1->value = chtcreate()) <= 0)
  384.                     {
  385.         fraerror( "cannot create character translation table");
  386.                     }
  387.                     prtequvalue("C: 0x%lx\n", $1 -> value);
  388.                 }
  389.                 else
  390.                 {
  391.             fraerror( "multiple definition of label");
  392.                 }
  393.             }
  394.     |        KOC_CHUSE
  395.             {
  396.                 chtcpoint = (int *) NULL;
  397.                 prtequvalue("C: 0x%lx\n", 0L);
  398.             }
  399.     |        KOC_CHUSE expr
  400.             {
  401.                 pevalexpr(0, $2);
  402.                 if( evalr[0].seg == SSG_ABS)
  403.                 {
  404.                     if( evalr[0].value == 0)
  405.                     {
  406.                         chtcpoint = (int *)NULL;
  407.                         prtequvalue("C: 0x%lx\n", 0L);
  408.                     }
  409.                     else if(evalr[0].value < chtnxalph)
  410.                     {
  411.                 chtcpoint = chtatab[evalr[0].value];
  412.                 prtequvalue("C: 0x%l